/*-------------------------------------------------------- 
* Module Name : OLButton
* Version : 1.0
* 
* Software Name : Qt App Template
* Version : 1.0
*
* Copyright � 2010 � 2011 France T�l�com
* This software is distributed under the LGPL v2.1 license,
* the text of which is available at http://www.gnu.org/licenses/lgpl-2.1.html
* or see the "LICENSE.txt" file for more details.
*
*--------------------------------------------------------
* File Name   : OLButton.h
*
* Created     : 07 June 2011
* Author(s)   : Omer Saleem
*
* Description :
* Object for a customised button used through-out the 
* framework in various elements. Can also be used by the
* application as a customised push button/panel.
*
*--------------------------------------------------------
* 1.0 - First open source release
*
*/

#ifndef OLBUTTON_H
#define OLBUTTON_H

#include <QWidget>
#include <QPair>

class OLPixmapWidget;
class QLabel;
class QHBoxLayout;

typedef QPair<QPixmap, QPixmap> ButtonIcons;

class OLButton : public QWidget
{
    Q_OBJECT
public:
    OLButton(QWidget *parent = 0);
    OLButton(const QString& text, QWidget *parent=0);

//    OLButton(OLPixmapWidget* icon, const QString& text, QWidget *parent=0);
//    OLButton(const QString& text, QWidget *parent=0);
//    OLButton(OLPixmapWidget* icon, QWidget *parent=0);

//    void setCustomLayout(QLayout *customLayout);
//    void setText(const QString& text, Qt::Alignment alignment);
//    void setIcon(const QString& icon, Qt::Alignment alignment = Qt::AlignCenter, const QString& highlightIcon = QString());
//    void setIcon(const QPixmap& icon, Qt::Alignment alignment = Qt::AlignCenter, const QPixmap& highlightIcon = QPixmap());

    // button configuration functions
    void textButton(const QString& text, Qt::Alignment alignment = Qt::AlignCenter);
    void iconButton(ButtonIcons icons, Qt::Alignment alignment = Qt::AlignCenter);
    void textIconButton(const QString& text, ButtonIcons icons, Qt::Alignment alignment = Qt::AlignCenter);
    void iconTextButton(ButtonIcons icons, const QString& text, Qt::Alignment alignment = Qt::AlignCenter);

public slots:
    void disable();
    void enable();
    void highlight();
    void unhighlight();
    void toggleHighlight();
    void transparent();
    void opaque();

    void hideIcon();
    void showIcon();
    void hideText();
    void showText();

    void setText(const QString& text);
    void setTextStyleSheet(const QString& style);
    void setIcon(const QPixmap& icon_up, const QPixmap& icon_down);

signals:
    void clicked();
    void pressedChanged(bool pressed);

protected:
    // from QWidget
    virtual void paintEvent(QPaintEvent* e);
    virtual void mousePressEvent(QMouseEvent* e);
    virtual void mouseReleaseEvent(QMouseEvent* e);
    virtual void mouseMoveEvent(QMouseEvent* e);

private:
    enum ButtonFlags
    {
        none = 0x00,
        pressed = 0x01,
        disabled = 0x02,
        highlighted = 0x04,
        background = 0x08
    };

    QHBoxLayout* baseContruct();

private:
    unsigned int m_flags;
    QLabel* m_text;
    QLabel* m_iconContainer;
    ButtonIcons m_icons;
};

#endif // OLBUTTON_H
